import {
  Controller,
  Get,
  Param,
  Delete,
  Query,
  Req,
  Body,
  Post,
} from '@nestjs/common';
import { ServiceService } from './service.service';
import { Public } from 'src/common/decorators/public.decorator';
import { ApiOperation, ApiProperty, ApiQuery } from '@nestjs/swagger';

@Controller('service_web')
export class ServiceController {
  constructor(private readonly serviceService: ServiceService) {}

  // @Post()
  // create(@Body() createServiceDto: CreateServiceDto) {
  //   return this.serviceService.create(createServiceDto);
  // }

  @Get(':id')
  @Public()
  @ApiProperty({ description: '根据ID获取服务详情信息' })
  findOne(@Param('id') id: string) {
    return this.serviceService.findOne(+id);
  }

  @Get()
  @ApiOperation({
    summary: '分页查询',
    description: '分页查询当前用户所在地区的服务信息',
  })
  @ApiQuery({ name: 'pageSize', description: '数据条数', required: true })
  @ApiQuery({ name: 'currentPage', description: '当前页码', required: true })
  @ApiQuery({ name: 'keywords', description: '关键词', required: false })
  skipFind(
    @Req() req,
    @Query('keywords') keywords,
    @Query('pageSize') pageSize,
    @Query('currentPage') currentPage,
  ) {
    if (req.managerInfo.city) {
      return this.serviceService.skipFind(
        +currentPage,
        +pageSize,
        req.managerInfo.city,
        keywords,
      );
    } else {
      return this.serviceService.skipFind(
        +currentPage,
        +pageSize,
        '成都',
        keywords,
      );
    }
  }

  @Post('add_service')
  addService(@Req() req, @Body() params) {
    const userId = req.managerInfo.sub;
    return this.serviceService.addService(userId, params);
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.serviceService.remove(+id);
  }
}
